package Heap;

import java.util.Arrays;
import java.util.Scanner;

public class Heap {

	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		System.out.println("How nany shops you have? ");
		
		int shops = sc.nextInt();
		 
		int choice = 1;
			
		int totalInd = 0;
				
		int[] arr = new int [shops + 1];
		
		
		while(choice != 0)
		{

		System.out.println( "For adding sum in shop press 1. \n" +
							"For total sum information press 2. \n" +
                  		    "For exit press 0. \n");
		
		choice = sc.nextInt();
		
			if (choice == 1)
			{
				addingSum(arr);
			}
				
			if (choice == 2)
			{
				returnInformation(arr, totalInd);
			}
				
			if (choice != 1 && choice != 2 && choice != 0)
			{
				System.out.println("Wrong number!"); 
				continue;
			}
		}
		System.out.println("Exit!");
		sc.close();
	}
	
		public static void addingSum(int[] arr)
		{
			
			Scanner sc = new Scanner (System.in);
			int shop = 0;
			
			while(shop == 0 || shop >= arr.length)
			{
			System.out.println("Enter the number of the shop you want to add sum ");
				shop = sc.nextInt();
				if(shop == 0 || shop >= arr.length)
				{
					System.out.println("Wrong number!");
					continue;
				}
			
			System.out.println("Enter the sum you want to add in shtop " + shop);
			
			int sum = sc.nextInt();
					
			arr[shop] += sum;
			}
		}

	public static void returnInformation ( int[]arr, int totalInd)
	{
		Scanner sc = new Scanner(System.in);
		boolean flag = true;
		int start = 0;
		int end = 0;
		
		while(flag == true)
		{
		System.out.println("Enter between which shops you want to get the sum information. ");

		start = sc.nextInt();
		end = sc.nextInt();
			if(start > totalInd && end < arr.length)
			{
				flag = false;
			}
		
		}
		
		for(int i = start; i <= end; i++)
		{
			arr[totalInd] += arr[2*totalInd+i];			
		}
		
		System.out.println("The total SUM in your chosen shops is : " + arr[totalInd]);
		System.out.println();
		arr[totalInd] = 0;
	}
	
	
}
